package fileReader.demo.reader;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.geom.Point2D;
import java.util.Vector;


/**
 * This class defines the common features of ESRI shapetypes
 *
 * @author Mari Puhakka
 * @version 0.1
 */
public class PolyLineDrawer extends LayerDrawer {

	protected Vector vertexList;
	protected String name;
	protected String riverName;
	private double depth;

	
	public PolyLineDrawer(){
		vertexList = new Vector();
	}
	
	
	/**
	 * This method removes every n'th vertex from  the polyline
	 * @param n removal rate
	 */
	public void reduceData(int n) {
		for(int i=0; i<vertexList.size(); i++)
		{
			if(i%n==0)
			{
				vertexList.remove(i);
			}
		}
	}

	
	
	public void Draw(Graphics g, double zoom, int xtrans, int ytrans, String layer) {
				
	     //polyline x and y coordinates
	     int []xcoord = new int[vertexList.size()];
	     int []ycoord = new int[vertexList.size()];
	     
	     double minX=MapLayer.getGlobalMin_x();
	     double maxX=MapLayer.getGlobalMax_x();
	     double minY=MapLayer.getGlobalMin_y();
	     double maxY=MapLayer.getGlobalMax_y();
	     
	     //scalex and scaley has to be the same for all the layers to get righ proportions
	     //scalex and scaley makes the map fit the screen
	     double scalex = 1600.0/(maxX-minX);//adapt this to your screen
	     double scaley = 900.0/(minY - maxY);//adapt this to your screen
	     
	     if(layer.contains("depthcontour")){
	    	 g.setColor(new Color(204, 204, 255));
			}
			else if(layer.contains("limitl")){
				g.setColor(Color.RED);
			}else if(layer.contains("pipeline")){
				g.setColor(Color.MAGENTA);
			}else {
				g.setColor(Color.BLACK); //TODO: VRI?
			}
	
	     for(int j = 0 ; j < vertexList.size() ; j++) {
	             Point2D cv = (Point2D) vertexList.elementAt(j);
	             //maps left top corners is set to left top corner on screen
	             xcoord[j] = (int) (((cv.getX() - minX)*(scalex))*zoom)+xtrans;
	             ycoord[j] = (int) (((cv.getY() - minY)*(scaley) +900.0)*zoom+ytrans);
	             
	     }
	     
	     if(layer.contains("roadnrailw")){
	    	 g.drawPolyline(xcoord,ycoord,vertexList.size());
	    	 //g.drawString(name, xcoord[(xcoord.length/2)], ycoord[(ycoord.length/2)]);
			}
			else if(layer.contains("river")){
				g.drawPolyline(xcoord,ycoord,vertexList.size());
		    	// g.drawString(riverName, xcoord[(xcoord.length/2)], ycoord[(ycoord.length/2)]);
			}else {
				g.drawPolyline(xcoord,ycoord,vertexList.size());
			}
	     
	 }

	/**
	 * This is a getter method for vertexList.
	 * @return vertex list pointer
	 */
	public Vector getVertexList() {
		return vertexList;
	}

	/**
	 * @return Returns the riverName.
	 */
	public String getRiverName() {
		return riverName;
	}

	/**
	 * @param riverName The riverName to set.
	 */
	public void setRiverName(String riverName) {
		this.riverName = riverName;
	}


	/**
	 * This is a setter method for depth.
	 * @param depth depth value to set
	 */
	public void setDepth(double depth) {
		this.depth=depth;		
	}


	/**
	 * @return Returns the depth.
	 */
	public double getDepth() {
		return depth;
	}

	/**
	 * 
	 * @param idRoad
	 */
	public void setRoadName(String idRoad) {
		name=idRoad;
	}

}
